<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/11/24
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="session"/>
<!DOCTYPE html>

<html>
<head>
    <title>资金管理</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="${path}/plugins/jquery-easyui-1.4.1/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${path}/plugins/jquery-easyui-1.4.1/themes/icon.css">
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
    <script language="javascript" type="text/javascript" src="${path}/plugins/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
        $(function(){
            //查询
            $("#search_tx").click(function(){


                var currenttab =  $("#search_tx").attr("stab");
                $('#'+currenttab).datagrid('load',{
                    withdraw_id:$("#withdrawId").val(),
                    withdraw_status:$("#withdrawStatus").combobox("getValue")
                });
            });
            $("#search_pt").click(function(){


                var currenttab =  $("#search_pt").attr("stab");
                $('#'+currenttab).datagrid('load',{
                    beginTime:$("#platformBeginTime").val(),
                    endTime:$("#platformEndTime").val(),
                    costType:$("#platformCostType").combobox("getValue")
                });
                f_findCountPlatformFinance();
            });
            $("#search_yh").click(function(){


                var currenttab =  $("#search_yh").attr("stab");
                $('#'+currenttab).datagrid('load',{
                    beginTime:$("#userBeginTime").val(),
                    endTime:$("#userEndTime").val(),
                    costType:$("#userCostType").combobox("getValue")
                });

                f_findCountUserFinance();

            });
            //切换
            $('#tabs').tabs({
                onSelect: function (title) {
                    if(title=="资金管理"){
                        $('#ttAll').datagrid({
                            url:'${path}/fundManage/withdraw.do?withdraw_id='+$("#withdrawId").val(),
                            method:'get'
                        });
                        $("#search").attr("stab","ttAll");
                    }else if(title=="平台财务报表"){
                        $('#ttptcwbb').datagrid({
                            url:'${path}/platformFinance/findPlatformFinanceReport.do',
                            method:'post',
                            queryParams:{
                                beginTime:$("#platformBeginTime").val(),
                                endTime:$("#platformEndTime").val(),
                                costType:$("#platformCostType").combobox("getValue")
                            }
                        });
                        $("#search_pt").attr("stab","ttptcwbb");

                        f_findCountPlatformFinance();
                    }else if(title=="用户财务报表"){
                        $('#ttyhcwbb').datagrid({
                            url:'${path}/userFinance/findUserFinanceReport.do',
                            method:'post',
                            queryParams:{
                                beginTime:$("#userBeginTime").val(),
                                endTime:$("#userEndTime").val(),
                                costType:$("#userCostType").combobox("getValue")
                            }
                        });
                        $("#search_yh").attr("stab","ttyhcwbb");

                        f_findCountUserFinance();
                    }
                }
            });
        });
        //提现审核---同意
        function f_agree(user_name,money,withdraw_id){
            if(confirm("是否已为" + user_name + " 打款" + money +"？")) {
                $.post("${path}/fundManage/changeWithdrawStatus.do",{
                    withdrawId:withdraw_id,withdrawStatus:130103
                },function(data){
                    if(data.errormsg == undefined){
                        $('#ttAll').datagrid('reload');
                    }else{
                        alert(data.errormsg);
                    }
                },"json");
            }
        }
        //提现审核---打回
        function f_callBack(user_name,withdraw_id){
            if(confirm("是否打回" + user_name + " 申请的提现？")) {
                $.post("${path}/fundManage/changeWithdrawStatus.do",{
                    withdrawId:withdraw_id,withdrawStatus:130102
                },function(data){
                    if(data.errormsg == undefined){
                        $('#ttAll').datagrid('reload');
                    }else{
                        alert(data.errormsg);
                    }
                },"json");
            }
        }

        //平台财务报表--查询统计平台财务汇总数据
        function f_findCountPlatformFinance(){
            $.post("${path}/platformFinance/findCountPlatformFinance.do",{
                beginTime:$("#platformBeginTime").val(),
                endTime:$("#platformEndTime").val(),
                costType:$("#platformCostType").combobox("getValue")
            },function(data){
                if(data.errormsg == undefined){

                    $("#ptcwSumPrice").html(data.sumPrice);

                }else{
                    alert(data.errormsg);
                }
            },"json");

        }
        //用户财务报表--查询统计用户财务汇总数据
        function f_findCountUserFinance(){

            $("#yhczSumPrice").html("0");
            $("#yhtxSumPrice").html("0");
            $.post("${path}/userFinance/findCountUserFinance.do",{
                beginTime:$("#userBeginTime").val(),
                endTime:$("#userEndTime").val(),
                costType:$("#userCostType").combobox("getValue")
            },function(data){
                if(data.errormsg == undefined){

                    for(var i = 0; i < data.sumPriceList.length;i++){

                        var bean = data.sumPriceList[i];

                        //充值
                        if(112101 == bean.type){

                            $("#yhczSumPrice").html(bean.sumMoney);

                        }
                        if(112106 == bean.type){//提现
                            $("#yhtxSumPrice").html(bean.sumMoney);
                        }


                    }



                }else{
                    alert(data.errormsg);
                }
            },"json");

        }


    </script>
</head>
<body class="easyui-layout">
<div region="center" style="padding:5px;" border="false">
    <div id="tabs" class="easyui-tabs" style="width:100%;height: 650px;">
        <div title="提现审核" style="padding:10px">
            <!--列表-->
            <table id="ttAll" class="easyui-datagrid" title="提现审核"
                   data-options="singleSelect:true,collapsible:true,url:'${path}/fundManage/withdraw.do',
       method:'get',toolbar:'#txbh',pagination:'true',fit:'true'">
                <thead>
                <tr>
                    <th data-options="field:'withdraw_id',align:'center',width:180">用户提现编号</th>
                    <th data-options="field:'user_name',align:'center',width:180">用户账号</th>
                    <th data-options="field:'money',align:'center',width:180">提现金额</th>
                    <th data-options="field:'apply_time',align:'center',width:180">申请日期</th>
                    <th data-options="field:'alipayAccount',align:'center',width:180">支付宝账号</th>
                    <th data-options="field:'withdraw_status',align:'center',width:80,formatter: rowformatter1">状态</th>
                    <th data-options="field:'cz',align:'center',width:180,formatter: rowformatter">操作</th>
                </tr>
                </thead>
            </table>
        </div>
        <div title="平台财务报表" style="padding:10px">
            <table id="ttptcwbb" class="easyui-datagrid" title="平台财务报表"
                   data-options="singleSelect:true,collapsible:true,url:null,
       method:'get',toolbar:'#ptcybb',pagination:'true',fit:'true'">
                <thead>
                <tr>
                    <th data-options="field:'finish_time',align:'center',width:180">完成时间</th>
                    <th data-options="field:'user_name',align:'center',width:180">用户账号</th>
                    <th data-options="field:'price',align:'center',width:180">金额</th>
                    <th data-options="field:'type',align:'center',width:180,formatter: rowformatter2">类别</th>


                </tr>
                </thead>
            </table>
        </div>
        <div title="用户财务报表" style="padding:10px">
            <table id="ttyhcwbb" class="easyui-datagrid" title="用户财务报表"
                   data-options="singleSelect:true,collapsible:true,url:null,
       method:'get',toolbar:'#yhcwbb',pagination:'true',fit:'true'">
                <thead>
                <tr>
                    <th data-options="field:'time',align:'center',width:180">完成时间</th>
                    <th data-options="field:'user_name',align:'center',width:180">用户账号</th>
                    <th data-options="field:'money',align:'center',width:180">金额</th>
                    <th data-options="field:'type',align:'center',width:180">类别</th>
                    <th data-options="field:'remark',align:'center',width:280">备注</th>


                </tr>
                </thead>
            </table>
        </div>

    </div>
</div>
<!--提现审核 头工具项-->
<div id="txbh" style="padding:2px 5px;">
    提现编号: <input class="easyui-textbox" name="withdrawId" id="withdrawId" style="width:110px">
    处理状态:
            <select class="easyui-combobox" data-options="editable:false" name="withdrawStatus" id="withdrawStatus" style="width:110px">
                <option value="">所有</option>
                <option value="130101">待处理</option>
                <option value="130102">已打回</option>
                <option value="130103">打款成功</option>
            </select>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="search_tx" stab="ttAll">查找</a>
</div>
<!--平台财务报表 头工具项-->
<div id="ptcybb" style="padding:2px 5px;">
    开始时间: <input placeholder="请选择开始时间"  type="text" id="platformBeginTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    结束时间: <input placeholder="请选择结束时间"  type="text" id="platformEndTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    类别:
            <select class="easyui-combobox" data-options="editable:false" name="platformCostType" id="platformCostType" style="width:110px">
                <option value="">所有</option>
                <option value="1">作品手续费</option>
                <option value="2">项目手续费</option>
                <option value="3">竞赛活动手续费</option>
                <option value="4">项目增值服务费</option>
                <option value="5">竞赛活动增值服务费</option>
            </select>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="search_pt" stab="ttptcwbb">查找</a>
    <br/>
    <h3 style="color: #0000ff;">金额合计：<span id="ptcwSumPrice" style="color: red;">统计中...</span></h3>
</div>
<!--用户财务报表 头工具项-->
<div id="yhcwbb" style="padding:2px 5px;">
    开始时间: <input placeholder="请选择开始时间"  type="text" id="userBeginTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    结束时间: <input placeholder="请选择结束时间"  type="text" id="userEndTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" />
    类别:
            <select class="easyui-combobox" data-options="editable:false" id="userCostType" style="width:110px">
                <option value="">所有</option>
                <option value="112101">充值</option>
                <option value="112102">推广收入</option>
                <option value="112103">任务收入</option>
                <option value="112104">活动竞赛收入</option>
                <option value="112105">作品收入</option>
                <option value="112106">提现</option>
                <option value="112107">项目支出</option>
                <option value="112109">购买作品</option>
                <option value="112110">冻结余额</option>
                <option value="112111">竞赛活动支出</option>
                <option value="112112">增值服务支出</option>
                <option value="112108">其他</option>

            </select>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="search_yh" stab="ttyhcwbb">查找</a>
    <br/>
    <h3 style="color: #0000ff;">充值合计：<span id="yhczSumPrice" style="color: red;">统计中...</span>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        提现合计：<span id="yhtxSumPrice" style="color: red;">统计中...</span>
    </h3>
</div>
<script>

    //提现审核---操作
    function rowformatter(value,row,index){

        if(row.withdraw_status == 130101){
            return  "<a href='javascript:void(0)' onclick=\"f_agree(\'"+row.user_name+"\',"+row.money+","+row.withdraw_id+")\">已完成打款</a> " +
                    "<a href='javascript:void(0)' onclick=\"f_callBack(\'"+row.user_name+"\',"+row.withdraw_id+")\">打回</a> " ;
        }

        return  "";
    }
    ////提现审核---格式化状态
    function rowformatter1(value,row,index){

        if(value == 130101){
            return  "待处理";
        }else if(value == 130102){
            return  "已打回";
        }else if(value == 130103) {
            return  "打款成功";
        }

        return  value;
    }
    //平台财务报表---类别
    function rowformatter2(value,row,index){

       switch (value){
           case 1 :
               return "作品手续费";
           case 2 :
               return "项目手续费";
           case 3 :
               return "竞赛活动手续费";
           case 4 :
               return "项目增值服务费";
           case 5 :
               return "竞赛活动增值服务费";
           default :
               return value;
       }

    }
    function rowformatter4(value,row,index){
        var str = "";
        return  '<a href="#" onclick="examine('+row.id+',\''+row.title+'\','+index+')">审核通过</a>&nbsp;&nbsp;';
    }
    function rowformatter5(value,row,index){
        if(row.isRecom == 101001){
            return '<a href="#" onclick="unrecommend('+row.id+',\''+row.title+'\','+index+')">取消推荐</a>';
        }else{
            return '<a href="#" onclick="recommend('+row.id+',\''+row.title+'\','+index+')">推荐</a>';
        }

    }
</script>
</body>
</html>
